//
// Created by dgy on 2022/9/23.
//
#include "iostream"
using namespace std;
struct people{
    int rank;
    char color;
    char name;
};
//定义颜色的类别
char color[24][4];
int num=0;
//定义排名的类别
int rankpeople[24][4];
int sum=0;

void swap(int &a,int &b){
    int temp=a;
    a=b;
    b=temp;
}
void perm(char list[],int low,int high){
    if(low==high){   //当low==high时,此时list就是其中一个排列,输出list
        for(int i=0;i<=low;i++){
            color[num][i]=list[i];
        }
        num++;
    }else{
        for(int i=low;i<=high;i++){//每个元素与第一个元素交换
            swap(list[i],list[low]);
            perm(list,low+1,high); //交换后,得到子序列,用函数perm得到子序列的全排列
            swap(list[i],list[low]);//最后,将元素交换回来,复原,然后交换另一个元素
        }
    }
}
//对Int进行全排列
void permInt(int list[],int low,int high){
    if(low==high){   //当low==high时,此时list就是其中一个排列,输出list
        for(int i=0;i<=low;i++){
            rankpeople[sum][i]=list[i];
        }
        sum++;
    }else{
        for(int i=low;i<=high;i++){//每个元素与第一个元素交换
            swap(list[i],list[low]);
            permInt(list,low+1,high); //交换后,得到子序列,用函数perm得到子序列的全排列
            swap(list[i],list[low]);//最后,将元素交换回来,复原,然后交换另一个元素
        }
    }
}

int main(){
    int final;
    people people[4];
    people[0].name='m';
    people[1].name='e';
    people[2].name='h';
    people[3].name='f';
    char colour[4]={'r','p','b','g'};
    perm(colour,0,3);
    int ranking[4]={1,2,3,4};
    permInt(ranking,0,3);
    for (int i = 0; i < 24 ; ++i) {
        //对于每个人自行车颜色的种类情况
        people[0].color=color[i][0];
        people[1].color=color[i][1];
        people[2].color=color[i][2];
        people[3].color=color[i][3];
        //cout<<color[i][0]<<color[i][1]<<color[i][2]<<color[i][3]<<endl;

        for (int j = 0; j < 24; ++j) {
            //在上面确定的颜色的情况下，排名的情况
            people[0].rank=rankpeople[j][0];
            people[1].rank=rankpeople[j][1];
            people[2].rank=rankpeople[j][2];
            people[3].rank=rankpeople[j][3];

            //cout<<rankpeople[j][0]<<endl;
            //cout<<people[0].rank<<people[1].rank<<people[2].rank<<people[3].rank<<endl;
            //接下来在题目给出的条件下判断是否成立
            //前两个条件
            if(people[1].color=='p'&&people[2].color!='g'&&people[0].rank!=1&&people[0].rank!=4&&people[1].rank!=1&&people[1].rank!=4){

                for (int k = 0; k < 4; ++k) {
                    //第三个条件
                    if(people[k].color=='b'&&people[k].rank<people[3].rank){
                        //找到骑绿色车的人
                        int greenpeople;
                        for (int l = 0; l < 4; ++l) {
                            if(people[l].color=='g'){
                                greenpeople=l;
                                break;
                            }
                        }
                        //找到骑紫色车的人
                        int purple;
                        for (int m = 0; m < 4; ++m) {
                            if(people[m].color=='p'){
                                purple=m;
                                break;
                            }
                        }
                        if (people[greenpeople].rank<people[purple].rank){
                            //寻找第二名
                            for (int l = 0; l < 4; ++l) {
                                if(people[l].rank==2){
                                    for (int m = 0; m < 4; ++m) {
                                        cout<<"name:"<<people[m].name<<" color:"<<people[m].color<<" rank:"<<people[m].rank<<endl;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        
    }
}
